layui.use(['form', 'table', 'layer', 'laydate'], function (form, table, layer, laydate) {

    form.render();

    //获取表单数据
    let searchCondition = {"userId": parseInt(Base64.decode(getToken()))};

    function getSearchCodition() {
        return searchCondition;
    }

    var recordTable = table.render({
        elem: '#recordList',
        url: '../record/all',
        height: 460,
        cellMinWidth: 95,
        page: true,
        // limits: [10, 15, 20, 25],
        limit: 10,
        loading: true,
        contentType: "application/json;charset=utf-8",
        id: "recordListTable",
        method: 'post',
        where: getSearchCodition(),
        //res 即为原始返回的数据
        parseData: function (res) {
            console.log(res);
            return {
                "code": res.code,
                "count": res.count,
                "data": res.data
            };
        },
        text: {
            none: '您还未打卡...暂无数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
        },
        done: function (res, curr, count) {
            $(".layui-laypage-limits").hide();
            // if (count === 0) {
            //     $(".layui-none").html("您还未打卡...");
            // }
            if (curr > 1 && null == res.data) {
                curr = curr - 1;
                table.reload('paper-info', {
                    //设定异步数据接口的额外参数，任意设
                    where: {},
                    page: {
                        curr: curr
                    }
                });
            }
        },
        cols: [[
            {type: "radio", fixed: "left", width: 50},
            {field: 'id', title: 'id', minWidth: 50, align: "center", hide: true},
            {field: 'username', title: '用户名', width: 100, minWidth: 100, align: "center"},
            {field: 'begintime', title: '上班时间', minWidth: 149, align: "center"},
            {field: 'endtime', title: '下班时间', minWidth: 149, align: "center"},
            {
                field: 'status', title: '状态', minWidth: 149, align: "center", templet: function (d) {
                    switch (d.status) {
                        case 0:
                            return '<span style="background-color: #00FF00;opacity: 0.5;color: white">正常</span>';
                            break;
                        case 1:
                            return '<span style="background-color: #FFB800;color: white">迟到</span>';
                            ;
                            break;
                        case 2:
                            return '<span style="background-color: #ff6700;opacity: 0.5;color: white">早退</span>';
                            break;
                        case 3:
                            return '<span style="background-color: #CF1900;opacity: 0.5;color: white">旷工</span>';
                            break;

                    }
                }
            },
            {field: 'phone', title: '手机', minWidth: 149, align: "center"}
        ]]
    });

    //重新加载表格
    function reload() {
        //组装查询条件
        searchCondition = {
            searchCondition: {
                search: $("#search").val(),
                "userId": parseInt(Base64.decode(getToken()))
            }
        };
        //重新加载表格
        recordTable.reload({
            where: searchCondition,
            page: {
                curr: 1  //重新从第一页开始加载
            }
        });
    }

    //查询按钮监听
    form.on("submit(querySubmit)", function () {
        reload();
    });

});